﻿using Confluent.Kafka;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LJ.EventBus.FastDog.Transport.Kafka;

public class EventBusTransportConfig
{
    public string Servers { get; set; } = null!;


    /// <summary>
    /// librdkafka configuration parameters (refer to https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md).
    /// <para>
    /// Topic configuration parameters are specified via the "default.topic.config" sub-dictionary config parameter.
    /// </para>
    /// </summary>
    public Dictionary<string, string> MainConfig { get;  set; }=[];

    /// <summary>
    /// Producer connection pool size, default is 10
    /// </summary>
    public int ConnectionPoolSize { get;  set; } = 10;
    public EventBusTransportTopicConfig Topic { get; set; } = new();


    /// <summary>
    /// New retriable error code (refer to
    /// https://docs.confluent.io/platform/current/clients/librdkafka/html/rdkafkacpp_8h.html#a4c6b7af48c215724c323c60ea4080dbf)
    /// </summary>
    public List<ErrorCode> RetriableErrorCodes { get; set; } =
        [
            ErrorCode.GroupLoadInProgress,
            ErrorCode.Local_Retry,
            ErrorCode.RequestTimedOut,
            ErrorCode.LeaderNotAvailable,
            ErrorCode.NotLeaderForPartition,
            ErrorCode.RebalanceInProgress,
            ErrorCode.NotCoordinatorForGroup,
            ErrorCode.NetworkException,
            ErrorCode.GroupCoordinatorNotAvailable
];
}


public class EventBusTransportTopicConfig
{
    /// <summary>
    /// The number of partitions for the new topic
    /// </summary>
    public short NumPartitions { get; set; } = -1;

    /// <summary>
    /// The replication factor for the new topic
    /// </summary>
    public short ReplicationFactor { get; set; } = -1;
}